﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using cebao.DBUtility;//Please add references
namespace cebao.DAL
{
	/// <summary>
	/// 数据访问类:userinfo
	/// </summary>
	public partial class wuserinfo
	{
		public wuserinfo()
		{}
		#region  BasicMethod
	
		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select count(1) FROM Vfusernums ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            object obj = null;
            try
            {
                DbHelperSQL.connectionString = PubConstant.GetConnectionString("weatheruser");
                obj = DbHelperSQL.GetSingle(strSql.ToString());
                
            }
            catch (Exception)
            {


            }

            finally
            {
                DbHelperSQL.connectionString = PubConstant.ConnectionString;

            }
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
                strSql.Append("order by T.UserName desc");
			}
            strSql.Append(")AS Row,[KeyId],[UserName],[Email],[TrueName],[Mobile],[QQ],[f_name],[ulevel],[madd],mmark,mq_indexCode,mq_ip,mq_port,mq_password,mq_username from Vfusernums T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            DataSet ds=null;
            try
            {
                DbHelperSQL.connectionString = PubConstant.GetConnectionString("weatheruser");
                ds = DbHelperSQL.Query(strSql.ToString());
            }
            catch (Exception ex)
            {
                               
            }
            finally
            {
                DbHelperSQL.connectionString = PubConstant.ConnectionString;
            }
            return ds;
		}       
		#endregion  BasicMethod		
	}
}

